﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Dashboard.ClusteringSvc;

namespace Dashboard
{
    public class DocumentDetail
    {
        public int ClusterID { get; set; }
        public string ClusterDesc { get; set; }
        public int DocID { get; set; }
        public string Title { get; set; }
    }

    public partial class ClusterGrid : UserControl
    {
        public ClusterGrid()
        {
            InitializeComponent();
        }

        public void LoadClusterResult(DocumentClusteringOutput result)
        {
            List<DocumentDetail> docDetails = new List<DocumentDetail>();
            foreach(int clusterID in result.ClusteredDocs.Keys)
            {
                string clusterDesc = string.Format(
                    "{0} ({1}): {2}",
                    clusterID, 
                    Math.Round(result.ClusterDiameters[clusterID], 2),
                    result.ClusterLabels[clusterID]);
                foreach(int docID in result.ClusteredDocs[clusterID])
                {
                    DocumentDetail docDetail=new DocumentDetail()
                                                 {
                                                     ClusterID=clusterID,
                                                     ClusterDesc=clusterDesc,
                                                     DocID=docID,
                                                     Title=result.DocTitles[docID]
                                                 };
                    docDetails.Add(docDetail);
                }
            }
            this.dgClusters.ItemsSource = docDetails;
            //this.dgClusters.GroupDescriptions.Clear();
            //if(result.ClusteredDocs.Count>1)
            //{
            //    this.dgClusters.GroupDescriptions.Add(new PropertyGroupDescription("ClusterID"));
            //}
        }
    }
}
